package com.dk.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.dk.pojo.TRole;
import com.dk.service.RoleService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("role")
public class RoleController {
    @Reference//用这个注解来远程调用service而不是Autowired
    private RoleService roleService;
    @RequestMapping("toShow")
    public String toShow(){
        return "role/show";
    }
    @RequestMapping("toAdd")
    public String toAdd(){
        return "role/add";
    }

    @RequestMapping("addInfo")
    @ResponseBody
    public Boolean addInfo(@RequestParam("nodeIds")Integer[] nodeIds, TRole role){
        boolean b = roleService.addinfo(role,nodeIds);
        return b;
    }
    @RequestMapping("getInfo")
    @ResponseBody
    public List<TRole> getinfo (){
        List<TRole> list = roleService.getinfo();
        return list;
    }
    @RequestMapping("deleteInfo/{roleId}")
    @ResponseBody
    public Boolean deleteInfo(@PathVariable("roleId")Integer roleId){
        boolean b = roleService.deleteInfo(roleId);
        return b;
    }
  @RequestMapping("toUpdate/{id}")
    public String toUpdate(Model model,@PathVariable("id")Integer id){
      TRole getinfo = roleService.getInfo(id);
      model.addAttribute("list",getinfo);
      return "role/update";
  }
    @RequestMapping("updateInfo")
    @ResponseBody
    public boolean updateInfo(@RequestParam("nodeIds")Integer[] nodeIds, TRole tRole){
        boolean b  = roleService.updateInfo(nodeIds,tRole);
        return b;
    }

}
